package com.fuhe.chen.vendingmachine.controller.admin;

import com.fuhe.chen.vendingmachine.constant.MessageConstant;
import com.fuhe.chen.vendingmachine.dto.ApiResponse;
import com.fuhe.chen.vendingmachine.dto.CommoditySalesVolumeData;
import com.fuhe.chen.vendingmachine.dto.OrdersMonthVolume;
import com.fuhe.chen.vendingmachine.dto.PlatformData;
import com.fuhe.chen.vendingmachine.service.IStatisticService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * 数据中心
 */
@Controller
@Api(tags = "平台数据中心")
@RequestMapping("/admin/statistic")
public class StatisticController {

    @Autowired
    IStatisticService statisticService;

    @GetMapping("")
    @ApiOperation("平台数据汇总")
    @ResponseBody
    public ApiResponse<PlatformData> statistic(){
        Map<String, String> commodityData = statisticService.CommodityData();
        Map<String, String> orderData = statisticService.OrderData();
        Map<String, Integer> machineStatusData = statisticService.MachineStatusData();
        List<OrdersMonthVolume> volumes = statisticService.OrdersMonthVolume();
        List<CommoditySalesVolumeData> commoditySalesVolumeData = statisticService.CommoditySalesVolumeData();

        PlatformData data = new PlatformData();
        data.setCommodityData(commodityData);
        data.setCommoditySalesVolumeData(commoditySalesVolumeData);
        data.setMachineStatusData(machineStatusData);
        data.setOrderData(orderData);
        data.setVolumes(volumes);

        ApiResponse<PlatformData> response = new ApiResponse<>();
        response.setSuccess(true);
        response.setCode(MessageConstant.Success.SUCCESS_CODE);
        response.setMessage(MessageConstant.Success.QUERY_SUCCESS_MESSAGE);
        response.setData(data);
        return response;
    }
}
